window.onload = function (){
	document.getElementById("MemberResumeNote").onkeyup();
	document.getElementById("MemberResumenowIncome").onchange();
	var hidlist = new Array('MemberEducation','MemberWork','MemberExpWorktype');
	for(var i=0; i<hidlist.length; i++){
		var hidemoebtn = document.getElementsByName("btnAdd"+hidlist[i]);
		var conut =10;
		if(hidlist[i]=='MemberExpWorktype'){
			conut =3;
		}
		if(hidemoebtn.length == conut){
			Element.hide(hidemoebtn[i]);
		}
	}
	
	var datalength = document.getElementById('MemberWorkCount').value;
	for(var i=0; i<datalength;i++){
		disabledMonth(document.getElementById("MemberWorkExpWorkEndYear"+i),i);
	}
	var htmlvalid = document.getElementById('htmlValid').value;
	if(htmlvalid != ''){
		var obj = htmlvalid.split(",");
		for(var i=0; i<(obj.length);i++){
			document.getElementById(obj[i]).className = "wrong_color";
		}
	} 
	
}

function formatMoney(num,n)
{
	var oldNum = num;
	num = (num + "").replace(/[^\d\.-]/g, "");
	if(num == ''){
		 return oldNum;
	}
	num = parseFloat(num);

	num = num.toFixed(n) + "";  
    var re = /(-?\d+)(\d{3})/;
    while(re.test(num)) num = num.replace(re,"$1,$2")
    return num;
}

function formatMoney2(s, n)
{  
    n = n > 0 && n <= 20 ? n : 0;  
    s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";  
    var l = s.split(".")[0].split("").reverse(),  
    r = s.split(".")[1];  
    t = "";  
    for(i = 0; i < l.length; i ++ )  
    {  
    	t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");  
    }  
    return t.split("").reverse().join("") + "." + r;  
}

function returnMoney(s)  
{  
    return parseFloat(s.replace(/[^\d\.-]/g, ""));  
} 

function disabledMonth(op,index){
	if(op.value=='work_flg'){
		document.getElementById("MemberWorkExpWorkEndMonth"+index).disabled=true;
		document.getElementById("hidMemberWorkExpWorkEndMonth"+index).disabled=false;
		document.getElementById("hidMemberWorkExpWorkEndMonth"+index).value='';
	}else{
		document.getElementById("MemberWorkExpWorkEndMonth"+index).disabled=false;
		document.getElementById("hidMemberWorkExpWorkEndMonth"+index).disabled=true;
		document.getElementById("hidMemberWorkExpWorkEndMonth"+index).value='';
	}
}
Array.prototype.indexOf = function(val) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == val) return i;
    }
    return -1;
};
Array.prototype.remove = function(val) {
    var index = this.indexOf(val);
    if (index > -1) {
        this.splice(index, 1);
    }
};
String.prototype.trim = function() 
{ 
	return this.replace(/(^\s*)|(\s*$)/g, ""); 
}
String.prototype.format=function() 
{ 
	if(arguments.length==0) return this; 
	for(var s=this, i=0; i<arguments.length; i++) {
		s=s.replace(new RegExp("\\{"+i+"\\}","g"), arguments[i]); 
		return s; 
	}
};

function checkMultiLine(element,exp,count){
	var flag = false;
	var elements = $$('#'+element+' '+exp+'');
	//var elements = $$('#'+element+' '+exp+'','#'+element+' '+exp2+'');
	
	var ellength = elements.length;
	var elcount = (ellength/count);
	var ckcount = 0;
	var col = 0;
	for(var j = 1; j<=elcount; j++){
		var m = 0;
		for(var i = 1; i<=ellength; i+=count){
			flag = false;
			if(ckcount!=0)break;
			for(var g = 1; g<=count; g++){
				var element = elements[m];
				var elval = '';
				if(element.type=='text'){
					elval = element.value;
				}else{
					elval = element.options[element.options.selectedIndex].value;
				}
				if(elval != ''){
					ckcount = 0;
					flag = true;
				}
				if((elval == '') && !flag){
					ckcount = i;
				}
				m++;
			}
			col++;
		}
	}
	
	/*col = col == 0 ? 1 : col;
	if(!flag){
		alert('第{0}件目のデータが未入力です。'.format(col));
		return false;
	}else{
		return true;
	}*/
	
	col = col == 0 ? 1 : col;
	if(!flag){
		return col;
	}else{
		return 0;
	}

}

function checkWord(len,op){ 
	var str = op.value.trim();
	myLen =0;
	i=0;
	for(;(i<str.length)&&(myLen<=len*2);i++){
		if(str.charCodeAt(i)>0&&str.charCodeAt(i)<128){
			myLen++;
		}else{
			myLen+=2;
		}
	}
	var mydiv=document.getElementById("wordCheck");
	if(myLen>len*2){
		//@author wangyuhua 4/23 update start 注释下面的错误代码，重新改写代码
//		src.value=str.substring(0,i-1);
		str = str.substring(0,i-1);
		document.getElementById("MemberResumeNote").value = (str);
		//@author wangyuhua 4/23 update end
	}
	else{
		var word = Math.floor((len*2-myLen)/2);
		document.getElementById("MemberResumeNoteWord").value = (len-word);
		document.getElementById("wordCheck").innerHTML = "<span>"+word+"</span>";
	}
}
function getRealStyle(id,styleName) { 
	var element = document.getElementById(id); 
	var realStyle = null; 
	if (element.currentStyle) {
		realStyle = element.currentStyle[styleName]; 
	}
	else if (window.getComputedStyle) {
		realStyle = window.getComputedStyle(element,null)[styleName]; 
	}
	return realStyle; 
} 

var meArray = new Array(1,2,3,4,5,6,7,8,9);
function showMemberEducation(op,i){
	var ckinput = checkMultiLine('parentdivMemberEducation','input[type=text]',2);
	var ckselect = checkMultiLine('parentdivMemberEducation','select',6);
	if(ckinput != 0 && ckselect != 0){
		if(ckinput>ckselect){
			alert('{0}件目のデータが未入力です。'.format(ckinput));
		}else{
			alert('{0}件目のデータが未入力です。'.format(ckselect));
		}
		return false;
	}

	//var namelist = document.getElementsByName(op.parentNode.parentNode.parentNode.parentNode.parentNode.id);
	var namelist = document.getElementsByName("tableMemberEducation");
	var url = '/member/ajax_membereducation';
	var g = i;
	for(var j=0; j<=i; j++){
		meArray.remove(j);
	}
	i=meArray[0];
	meArray.remove(i);
	url = url +'?toid='+i+'&ofid='+g;
	
	if(namelist.length >= 10){
		Element.hide(op);
		return false;
	}else if(namelist.length == 1){
		var element = op.parentNode.parentNode.parentNode;
		Element.hide(element);
	}else{
		Element.hide(op);
	}

	var myAjax = new Ajax.Request(url,{
						            method: 'get', 
						            onComplete: function (response) {
						            	new Insertion.Before('ajax_membereducation', response.responseText); 
						            	if(namelist.length == 10){
						            		Element.hide("btnAddMemberEducation"+i);
						            	}
						            },
						            asynchronous:true, 
									evalScripts:true
									//parameters:$F('myMemberResumeMemberEducation')
        });
}
function hideMemberEducation(op,i,g){
	meArray.push(i);
	var element = op.parentNode.parentNode.parentNode.parentNode.parentNode;
	var listlength = document.getElementsByName(element.id).length;
	Element.remove(element);
	var addlist = document.getElementsByName("btnAddMemberEducation");
	Element.show(addlist[addlist.length-1].id);
	if(listlength<=2){
		Element.show("trAddMemberEducation");
	}
}

var mwArray = new Array(1,2,3,4,5,6,7,8,9);
function showMemberWork(op,i){
	var ckinput = checkMultiLine('parentdivMemberWork','input[type=text]',1);
	var ckselect = checkMultiLine('parentdivMemberWork','select',6);
	if(ckinput != 0 && ckselect != 0){
		if(ckinput>ckselect){
			alert('{0}件目のデータが未入力です。'.format(ckinput));
		}else{
			alert('{0}件目のデータが未入力です。'.format(ckselect));
		}
		return false;
	}
	
	var namelist = document.getElementsByName(op.parentNode.parentNode.parentNode.parentNode.parentNode.id);
	var url = '/member/ajax_memberwork';
	var g = i;
	for(var j=0; j<=i; j++){
		mwArray.remove(j);
	}
	i=mwArray[0];
	mwArray.remove(i);
	url = url +'?toid='+i+'&ofid='+g;
	
	if(namelist.length >= 10){
		Element.hide(op);
		return false;
	}else if(namelist.length == 1){
		var element = op.parentNode.parentNode.parentNode;
		Element.hide(element);
	}else{
		Element.hide(op);
	}
	var myAjax = new Ajax.Request(url,{
						            method: 'get',
						            onComplete: function (response) {
						            	new Insertion.Before('ajax_memberwork', response.responseText); 
						            	if(namelist.length == 10){
						            		Element.hide("btnAddMemberWork"+i);
						            	}
						            },
						            asynchronous:true, 
									evalScripts:true
        });
}
function hideMemberWork(op,i,g){
	mwArray.push(i);
	var element = op.parentNode.parentNode.parentNode.parentNode.parentNode;
	var listlength = document.getElementsByName(element.id).length;
	Element.remove(element);
	var addlist = document.getElementsByName("btnAddMemberWork");
	Element.show(addlist[addlist.length-1].id);
	if(listlength<=2){
		Element.show("trAddMemberWork");
	}
}

var mewArray = new Array(1,2);
function showMemberExpWorktype(op,i){
	var ckselect = checkMultiLine('parentdivMemberExpWorktype','select',4);
	if(ckselect != 0){
		alert('{0}件目のデータが未入力です。'.format(ckselect));
		return false;
	}
	var namelist = document.getElementsByName(op.parentNode.parentNode.parentNode.parentNode.parentNode.id);
	var url = '/member/ajax_member_exp_worktype';
	var g = i;
	for(var j=0; j<=i; j++){
		mewArray.remove(j);
	}
	i=mewArray[0];
	mewArray.remove(i);
	url = url +'?toid='+i+'&ofid='+g;
	
	if(namelist.length >= 3){
		Element.hide(op);
		return false;
	}else if(namelist.length == 1){
		var element = op.parentNode.parentNode.parentNode;
		Element.hide(element);
	}else{
		Element.hide(op);
	}
	var myAjax = new Ajax.Request(url,{
						            method: 'get', 
						            onComplete: function (response){
						            	new Insertion.Before('ajax_member_exp_worktype', response.responseText); 
						            	if(namelist.length == 3){
						            		Element.hide("btnAddMemberExpWorktype"+i);
						            		document.getElementById("MemberExpWorktypeNum").value=i;
						            	}
						            },
						            asynchronous:true, 
									evalScripts:true
        }
    );
}
function hideMemberExpWorktype(op,i,g){
	mewArray.push(i);
	var element = op.parentNode.parentNode.parentNode.parentNode.parentNode;
	var listlength = document.getElementsByName(element.id).length;
	Element.remove(element);
	var addlist = document.getElementsByName("btnAddMemberExpWorktype");
	Element.show(addlist[addlist.length-1].id);
	if(listlength<=2){
		Element.show("trAddMemberExpWorktype");
	}

}

